# _*_ coding:utf-8 _*_
# @author : Joyamon
# @time : 2022-12-14 12:44
# @file : user.py
import os
import requests
from apps import User
from exts import session



class UserTest(object):
    def __init__(self):
        self.data = {
            'username': '王明',
            'password': '123456',
            'repassword': '123456',
            'phone': '13480895062'
        }
        self.url = 'http://127.0.0.1:5000/user/'

    def register(self, route):

        res = requests.post(url=self.url + os.path.join(route), data=self.data)
        print(res.json())
        if res.json()['data']['username'] == self.data['username']:
            print('用户注册成功，用例通过')

    def login(self, route):
        data = {
            'username': self.data['username'],
            'password': self.data['password']
        }
        res = requests.post(url=self.url + os.path.join(route), data=data)
        print(res.json())
        if res.json()['message'] == '登录成功':
            print('用例通过')

    def del_user(self):
        user = session.query(User).filter(User.username == self.data['username']).sarlar()
        print(user)


if __name__ == '__main__':
    user = UserTest()
    user.register(route='register')
    user.login(route='login')
    user.login(route='delete')
